from selenium.webdriver.common.by import By
from base.base import Base
from selenium.webdriver import ActionChains
import time


class Page_UserList(Base):

    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[7]')
    topnav_nav_locator = (By.XPATH,'//span[text()="用户列表"]')
    user_name_locator = (By.XPATH,'//input[@placeholder="请输入用户名"]')
    real_name_locator = (By.XPATH,'//input[@placeholder="请输入姓名"]')
    search_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    reset_btn_locator = (By.XPATH,'//span[text()="重 置"]')
    list_locator = (By.XPATH,'//tbody//td[contains(@class,"ant-table-cell")]')
    search_empty_locator = (By.CLASS_NAME,'ant-empty-description')
    company_locator = (By.XPATH,'(//td//span[@role="img"])[1]')
    company_input_locator = (By.XPATH,'//input[@placeholder="请输入公司名称"]')
    confirm_btn_locator = (By.XPATH,'//span[text()="确 定"]')

    def page_jump(self):
        action = ActionChains(self.driver)
        action.move_to_element(self.find(self.topnav_locator)).perform()
        action.click(self.find(self.topnav_nav_locator)).perform()

    def get_list(self):
        elms = self.finds(self.list_locator)
        values = []
        for elm in elms:
            values.append(self.get_text_elm(elm))
        return values

    def input_username_search(self,username):
        self.input(self.user_name_locator,username)

    def input_realname_search(self,realname):
        self.input(self.real_name_locator,realname)
    
    def click_search_btn(self):
        self.click(self.search_btn_locator)

    def click_reset_btn(self):
        self.click(self.reset_btn_locator)

    def get_empty_text(self):
        return self.get_text(self.search_empty_locator)

    def click_company(self):
        self.click(self.company_locator)

    def input_company(self,company_name):
        self.input(self.company_input_locator,company_name)

    def click_confirm(self):
        self.click(self.confirm_btn_locator)
    